//
//  ConnectOffViewController.m
//  Light
//
//  Created by 骁唐 on 15/9/22.
//  Copyright (c) 2015年 骁唐. All rights reserved.
//

#import "ConnectOffViewController.h"
#import "AppDelegate.h"
#import "SliderViewController.h"
#import "HomeTwoViewController.h"
#import "constantDefinition.h"
#import "AppDelegate.h"
@interface ConnectOffViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *backGround;
@property (weak, nonatomic) IBOutlet UIView *homeBackView;
@property (weak, nonatomic) IBOutlet UIView *loginGotoView;

@end

@implementation ConnectOffViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (self.OffMark == YES)
    {//设置进入的
        self.loginGotoView.hidden = YES;
        [TJJ_SD_BLE_INSTRUCTIONS unBind:@"key"];
    }
    else
    {//注册进入的  no
        self.homeBackView.hidden = YES;
        [TJJ_SD_BLE_INSTRUCTIONS unBind:@"nokey"];

    }
//    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
//    delegate.myRemoveConnect = YES;
}

#pragma mark -
#pragma mark 导航返回
- (IBAction)homeBackClick {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark 跳过按钮
- (IBAction)gotoBtnClick {
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    delegate.Bluetooth = NO;//蓝牙未连接
    UserConfig *config = [UserConfig sharingUserConfig];
    [delegate.mgr stopScan];//停止搜索
    [config setConnectCool:@"0"];//未绑定
    
    BOOL HaveRoot = NO;//标记是否有Root
    for (UIViewController * controller in self.navigationController.viewControllers)
    {
        if ([controller isKindOfClass:[SliderViewController class]])
        {//如果是rootView
            HaveRoot = YES;
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
    if (!HaveRoot)
    {
        HomeTwoViewController *homet = [[HomeTwoViewController alloc] init];
        SliderViewController *slider = [SliderViewController sharedSliderController];
        if (SCREEN_WIDTH > 320)
        {//如果是6以及以上尺寸
            slider.LeftSContentOffset =  SCREEN_WIDTH-WIDTH_MAIN_6*SCREEN_SCALE;//SXW__设置侧边栏
        }
        else
        {//如果是6以下的手机屏幕
            slider.LeftSContentOffset =  SCREEN_WIDTH-WIDTH_MAIN*SCREEN_SCALE;//SXW__设置侧边栏
        }
        slider.LeftSContentScale = 1;//左视图缩小，1表示不缩小。
        UIStoryboard *userSt = [UIStoryboard storyboardWithName:@"User" bundle:nil];
        slider.LeftVC = [userSt instantiateViewControllerWithIdentifier:@"userViewId"];
        slider.MainVC = homet;
        UINavigationController *navigationVc = [[UINavigationController alloc]initWithRootViewController:slider];
        navigationVc.navigationBar.hidden = YES;
        delegate.window.rootViewController = navigationVc;
    }
}

#pragma mark -
#pragma mark 重新连接
- (IBAction)backClick {
//    [self dismissViewControllerAnimated:YES completion:nil];
//    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
//    [delegate.mgr cancelPeripheralConnection:delegate.peripheral];
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -
#pragma mark viewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
